﻿'
' DKP for DotNetNuke® - http://dkpdnn.codeplex.com
' Copyright (c) 2008
' by Casey Lengacher ( http://dkpdnn.codeplex.com )
'
' DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.
'

Imports DotNetNuke.Common.Utilities

Namespace DotNetNuke.Modules.tss_DKP

    Partial Public Class tss_DKP

        Inherits Entities.Modules.PortalModuleBase

        Implements Entities.Modules.IActionable

#Region "Private Variables"

        Private WithEvents ucBoards As tss_ucBoards
        Private WithEvents ucDrops As tss_ucDrops
        Private WithEvents ucInstances As tss_ucInstances
        Private WithEvents ucItems As tss_ucItems
        Private WithEvents ucLoots As tss_ucLoots
        Private WithEvents ucMobs As tss_ucMobs
        Private WithEvents ucPlayers As tss_ucPlayers
        Private WithEvents ucPlayerDetails As tss_ucPlayerDetails
        Private WithEvents ucRaids As tss_ucRaids
        Private WithEvents ucRosters As tss_ucRosters
        Private WithEvents ucTools As tss_ucTools

#End Region

#Region "Private Methods"

        Private Sub LoadUI()
            ucBoards = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucBoards.ascx")
            ucDrops = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucDrops.ascx")
            ucInstances = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucInstances.ascx")
            ucItems = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucItems.ascx")
            ucLoots = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucLoots.ascx")
            ucMobs = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucMobs.ascx")
            ucPlayers = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucPlayers.ascx")
            ucPlayerDetails = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucPlayerDetails.ascx")
            ucRaids = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucRaids.ascx")
            ucRosters = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucRosters.ascx")
            ucTools = Page.LoadControl("/DesktopModules/tss_DKP/tss_ucTools.ascx")

            ucBoards.Visible = False
            ucDrops.Visible = False
            ucInstances.Visible = False
            ucItems.Visible = False
            ucLoots.Visible = False
            ucMobs.Visible = False
            ucPlayers.Visible = False
            ucPlayerDetails.Visible = False
            ucRaids.Visible = False
            ucRosters.Visible = False
            ucTools.Visible = False

            ucBoards.ModuleConfiguration = Me.ModuleConfiguration
            ucDrops.ModuleConfiguration = Me.ModuleConfiguration
            ucInstances.ModuleConfiguration = Me.ModuleConfiguration
            ucItems.ModuleConfiguration = Me.ModuleConfiguration
            ucLoots.ModuleConfiguration = Me.ModuleConfiguration
            ucMobs.ModuleConfiguration = Me.ModuleConfiguration
            ucPlayers.ModuleConfiguration = Me.ModuleConfiguration
            ucPlayerDetails.ModuleConfiguration = Me.ModuleConfiguration
            ucRaids.ModuleConfiguration = Me.ModuleConfiguration
            ucRosters.ModuleConfiguration = Me.ModuleConfiguration
            ucTools.ModuleConfiguration = Me.ModuleConfiguration

            pnlContainer.Controls.Add(ucBoards)
            pnlContainer.Controls.Add(ucDrops)
            pnlContainer.Controls.Add(ucInstances)
            pnlContainer.Controls.Add(ucItems)
            pnlContainer.Controls.Add(ucLoots)
            pnlContainer.Controls.Add(ucMobs)
            pnlContainer.Controls.Add(ucPlayers)
            pnlContainer.Controls.Add(ucPlayerDetails)
            pnlContainer.Controls.Add(ucRaids)
            pnlContainer.Controls.Add(ucRosters)
            pnlContainer.Controls.Add(ucTools)
        End Sub

        Private Function ValidBoardID(ByRef strReason As String) As Boolean

            Dim tss_DKP As New tss_DataController

            If (Null.IsNull(Settings("BoardID"))) Then
                strReason = "Board undefined in module's settings."
                Return False
            Else
                Dim objExistingBoard As tss_BoardInfo = tss_DKP.tss_GetBoard(CInt(Settings("BoardID")))
                If (objExistingBoard Is Nothing) Then
                    strReason = "Board specified in module's settings not found."
                    Return False
                Else
                    Return True
                End If
            End If

        End Function

#End Region

#Region "Private Event Handlers"

        Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

            If Not (Page.IsPostBack) Then

                Dim strReason As String = Null.NullString

                If (DotNetNuke.Security.PortalSecurity.IsInRoles(Me.ModuleConfiguration.AuthorizedEditRoles)) And Not (UserId = -1) Then
                    lnkBoards.Enabled = True
                Else
                    lnkBoards.Enabled = False
                End If

                If (ValidBoardID(strReason)) Then
                    ucPlayers.Visible = True
                    lblBreadCrumb.Text = "You are here: Players"
                    ucPlayers.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If

            End If

        End Sub

        Private Sub Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkInstances.Click, lnkItems.Click, lnkMobs.Click, _
            lnkPlayers.Click, lnkRaids.Click, lnkTools.Click, lnkBoards.Click

            Dim strReason As String = Null.NullString

            For Each uc As Control In pnlContainer.Controls
                If (uc.Visible) Then
                    uc.Visible = False
                End If
            Next

            If (sender.Equals(lnkInstances)) Then
                If (ValidBoardID(strReason)) Then
                    ucInstances.Visible = True
                    lblBreadCrumb.Text = "You are here: Instances"
                    ucInstances.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkItems)) Then
                If (ValidBoardID(strReason)) Then
                    ucItems.Visible = True
                    lblBreadCrumb.Text = "You are here: Items"
                    ucItems.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkMobs)) Then
                If (ValidBoardID(strReason)) Then
                    ucMobs.Visible = True
                    lblBreadCrumb.Text = "You are here: Mobs"
                    ucMobs.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkPlayers)) Then
                If (ValidBoardID(strReason)) Then
                    ucPlayers.Visible = True
                    lblBreadCrumb.Text = "You are here: Players"
                    ucPlayers.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkRaids)) Then
                If (ValidBoardID(strReason)) Then
                    ucRaids.Visible = True
                    lblBreadCrumb.Text = "You are here: Raids"
                    ucRaids.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkTools)) Then
                If (ValidBoardID(strReason)) Then
                    ucTools.Visible = True
                    lblBreadCrumb.Text = "You are here: Tools"
                    ucTools.Initialize()
                Else
                    lblBreadCrumb.Text = strReason
                End If
            ElseIf (sender.Equals(lnkBoards)) Then
                If (DotNetNuke.Security.PortalSecurity.IsInRoles(Me.ModuleConfiguration.AuthorizedEditRoles)) And Not (UserId = -1) Then
                    ucBoards.Visible = True
                    lblBreadCrumb.Text = "You are here: Boards"
                    ucBoards.Initialize()
                End If
            End If

        End Sub

#End Region

#Region "Public Methods"

        Public Sub lnkManagePlayerDetails_Click(ByVal objPlayer As tss_PlayerInfo)

            ucPlayers.Visible = False
            ucPlayerDetails.Visible = True
            lblBreadCrumb.Text = "You are here: Players &#187; " + objPlayer.PlayerName + " &#187; Details"
            ucPlayerDetails.Initialize(objPlayer)

        End Sub

        Public Sub lnkManageMobDrops_Click(ByVal objMob As tss_MobInfo)

            ucMobs.Visible = False
            ucDrops.Visible = True
            lblBreadCrumb.Text = "You are here: Mobs &#187; " + objMob.MobName + " &#187; Drops"
            ucDrops.Initialize(objMob)

        End Sub

        Public Sub lnkManageRaidRosters_Click(ByVal objRaid As tss_RaidInfo)

            ucRaids.Visible = False
            ucRosters.Visible = True
            lblBreadCrumb.Text = "You are here: Raids &#187; " + objRaid.MobName + " (" + objRaid.RaidDate.ToString("MM/dd/yy hh:mm tt") + ") &#187; Rosters"
            ucRosters.Initialize(objRaid)

        End Sub

        Public Sub lnkManageRaidLoots_Click(ByVal objRaid As tss_RaidInfo)

            ucRaids.Visible = False
            ucLoots.Visible = True
            lblBreadCrumb.Text = "You are here: Raids &#187; " + objRaid.MobName + " (" + objRaid.RaidDate.ToString("MM/dd/yy hh:mm tt") + ") &#187; Loots"
            ucLoots.Initialize(objRaid)

        End Sub

        Public Sub lnkReturnToPlayers_Click()

            ucPlayerDetails.Visible = False
            ucPlayers.Visible = True
            lblBreadCrumb.Text = "You are here: Players"

        End Sub

        Public Sub lnkReturnToMobs_Click()

            ucDrops.Visible = False
            ucMobs.Visible = True
            lblBreadCrumb.Text = "You are here: Mobs"

        End Sub

        Public Sub lnkReturnToRaids_Click()

            ucLoots.Visible = False
            ucRosters.Visible = False
            ucRaids.Visible = True
            lblBreadCrumb.Text = "You are here: Raids"

        End Sub

#End Region

#Region "Web Form Designer Generated Code"

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub

        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
            LoadUI()
        End Sub

#End Region

#Region "Optional Interfaces"

        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                'Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), False, Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

#End Region

    End Class

End Namespace
